package com.itheima;


import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.itheima.pojo.Emp;
import org.apache.poi.ss.usermodel.HorizontalAlignment;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class WriteDemo2 {

    public static void main(String[] args) {

        WriteCellStyle cellStyle = new WriteCellStyle();
        cellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); //设置字体居中

        //设置字体样式
        WriteFont font = new WriteFont();
        font.setFontName("宋体");
        font.setFontHeightInPoints((short)12);
        cellStyle.setWriteFont(font);

        // 布局对象
        HorizontalCellStyleStrategy styleStrategy = new HorizontalCellStyleStrategy(cellStyle, cellStyle);

        List<List<String>> headers = new ArrayList<>();

        List<String> head1 = new ArrayList<>();
        head1.add("编号");

        List<String> head2 = new ArrayList<>();
        head2.add("姓名");

        List<String> head3 = new ArrayList<>();
        head3.add("年龄");

        List<String> head4 = new ArrayList<>();
        head4.add("性别");

        List<String> head5 = new ArrayList<>();
        head5.add("描述");

        headers.add(head1);
        headers.add(head2);
        headers.add(head3);
        headers.add(head4);
        headers.add(head5);


        List<List<String>> dataList = new ArrayList<>();
        dataList.add(Arrays.asList("0", "张三丰", "18", "男", "高手高手高高手"));
        dataList.add(Arrays.asList("1", "张无忌", "16", "男", "孤苦伶仃，爱美人不爱江山"));


        EasyExcel.write(new File("D:\\3.xls"))
                .head(headers)
                .excelType(ExcelTypeEnum.XLS)
                .registerWriteHandler(styleStrategy)
                .registerWriteHandler(new MyColumnStyle())
                .sheet(0)
                .doWrite(dataList);
    }
}
